<!--
 * @Author: kangjia kjhangzhou@163.com
 * @Date: 2022-09-29 09:57:51
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-10-13 18:29:12
 * @FilePath: \boss-web-applet\pages\service\order\details.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
	<view>
    <order-success v-if="orderStatusAssign==='create'" :title="$t('JLink.payTypeStatus.create')" :describe="$t('JLink.paySuccess.createSubText')" :customizeImg="true">
      <template #default>
        <image :src="`https://statics.xmcsrv.net/weixin/cloud/create.svg`" class="payStatusImg" mode="aspectFit"></image>
      </template>
    </order-success>
    <order-success v-if="orderStatusAssign==='pay'" :title="$t('JLink.paySuccess.paySuccessful')" :describe="$t('JLink.paySuccess.opening')"></order-success>
    <successButton></successButton>
  </view>
</template>

<script>
  import logins from '@/utils/loginApi.js'
  import orderStatus from "@/jvss/pageCloud/utils/pay"
  import { getOrderDetail } from '@/API/api.js'
  import orderSuccess from "../components/uni-success/index.vue"
  import successButton from './paySuccess/module/buttons.vue'

  const { handleLogin, httpReturn } = logins();
  const { orderStatusTime, handleClear } = orderStatus();
  export default {
    components: {
      orderSuccess,
      successButton
    },
    props:{

    },
    data() {
      return {
        orderStatusAssign: 'create'
      }
    },
    onLoad(opt) {
      const {orderId,referer} = opt;
      handleLogin(() => {
        this.handleOrderDetail(orderId)
      })
    },
    onShow() {

    },
    onUnload() {
      handleClear()
    },
    methods: {
      handleOrderDetail(orderId) {
        getOrderDetail({orderId}).then(res => {
          httpReturn(res, (data) => {
            const { status,channel,deviceId } = data;
            this.orderStatusAssign = status;//订单状态
            // '待开通' 和 '待支付' 定时查询支付状态
            if (status === "pay" || status === "create") {
              orderStatusTime(orderId, (payStatus,classifyId) => {
                this.orderStatusAssign = payStatus;//订单状态
				this.$routing(`${this.$pages.success}?tradeNo=${deviceId}&channel=${channel}&classifyId=${classifyId}`)
                // uni.navigateTo({
                //   url: '/jvss/pageCloud/service/order/paySuccess/success?tradeNo=${deviceId}&channel=${channel}&classifyId=${classifyId}'
                // });
              });
            }else{
              const {classifyId} = data;
              this.orderStatusAssign = 'finish';//已支付
			  this.$routing(`${this.$pages.success}?tradeNo=${deviceId}&channel=${channel}&classifyId=${classifyId}`)
              // uni.navigateTo({
              //   url: '/jvss/pageCloud/service/order/paySuccess/success?tradeNo=${deviceId}&channel=${channel}&classifyId=${classifyId}'
              // });
            }
          }, (code) => {})
        }).catch(()=>{})
      },
    }
  }
</script>
<style lang="less" scoped>
@import '@/common/style/main.css';
	.payStatusImg{
		width:54upx;
		height:54upx;
		vertical-align: middle;
	}
</style>